﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TanashCMS.Business.Utility;

public partial class services_Thumbnail : System.Web.UI.Page
{
    private string query(string key, string defaultValue)
    {
        return Request.QueryString[key] != null ? Request.QueryString[key] : defaultValue;
    }
    string imagePath { get { return query("i",""); } }
    string sizeX { get { return query("sx","1"); } }
    string sizeY { get { return query("sy","1"); } }
    string method { get { return query("method","stretch"); } }
    string centerX { get { return query("cx","0.5"); } }
    string centerY { get { return query("cy","0.5"); } }
    
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected override void Render(HtmlTextWriter writer)
    {
        Response.Clear();
        FillMethod fillMethod =
            method == "crop" ? FillMethod.Crop : 
                method == "stretch" ? FillMethod.Stretch : 
                    method == "stretchtosize" ? FillMethod.StretchToSize :
                        method == "restricttosize" ? FillMethod.RestrictToSize :
                            FillMethod.CropToSize;
        Thumbnailer thumb = new Thumbnailer(int.Parse(sizeX), int.Parse(sizeY), fillMethod, imagePath, "~/swa/i/image_not_found.jpg", Response, float.Parse(centerX), float.Parse(centerY));
        thumb.Process();

        //base.Render(writer);
    }
}
